package handler;

import com.alibaba.fastjson.JSON;
import com.github.timeloveboy.moeserver.DefaultHandle;
import com.github.timeloveboy.moeserver.IHttpRequest;
import com.github.timeloveboy.moeserver.IHttpResponse;
import com.github.timeloveboy.utils.FileUtil;
import com.github.timeloveboy.utils.UrlUtil;
import data.staticdata;

import java.io.File;
import java.io.IOException;
import java.util.Map;

/**
 * Created by root on 17-6-17.
 */

public class coach extends DefaultHandle {
    @Override
    public void POST(IHttpRequest req, IHttpResponse resp) throws IOException {
        Map<String, String> query_para = UrlUtil.splitQuery(req.getUrl().getQuery());
        if (query_para.get("id") == null) {
            String result = JSON.toJSONString(staticdata.computing.get().coaches);
            resp.write(result);
        } else {
            Integer id = Integer.parseInt(query_para.get("id"));
            String result = JSON.toJSONString(staticdata.computing.get().coaches.get(id));
            resp.write(result);
        }
    }

    public void GET(IHttpRequest req, IHttpResponse resp) throws IOException {
        resp.write(FileUtil.getContent(new File("static/html/coach.html")));
    }
}